package ch10_thread.thread;

/**
 * 不想或无法传递，进行恢复中断
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class StopRightWay02 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (true) {
                System.out.println("go");
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("中断");
                    break;
                }
                reInterMethod();
            }
        });
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }

    private static void reInterMethod() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // 不应屏蔽中断
            Thread.currentThread().interrupt();
            e.printStackTrace();
        }
    }
}
